package com.lingshu.app.base;

import android.content.res.Resources;

import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.lingshu.app.R;
import com.lingshu.app.config.App;
import com.lingshu.app.config.LoadState;
import com.lingshu.app.model.HttpBaseResponse;
import com.lingshu.app.model.auth.AuthUserBean;

/**
 * @author 于定金
 * @version 1.0
 * @Date 2023/12/28 13:50
 * @Description
 */
public abstract class BaseViewModel extends ViewModel implements DefaultLifecycleObserver {
    public Resources resources;

    /**
     * 标题
     */
    public final MutableLiveData<String> title = new MutableLiveData<>();

    /**
     * 加载状态
     */
    public final MutableLiveData<LoadState> loadState = new MutableLiveData<>();

    /**
     * 错误信息
     */
    public final MutableLiveData<String> errorMsg = new MutableLiveData<>(getResources().getString(R.string.load_error));

    /**
     * 通知信息
     */
    public final MutableLiveData<String> infoMsg = new MutableLiveData<>();

    /**
     * Token是否有效
     */
    public final MutableLiveData<Boolean> tokenIsValid = new MutableLiveData<>();

    /**
     * 登录结果
     */
    public final MutableLiveData<HttpBaseResponse<AuthUserBean>> loginResult = new MutableLiveData<>();

    /**
     * 是否为刷新数据
     */
    public boolean mRefresh;

    /**
     * 重新加载数据。没有网络，点击重试时回调
     */
    public void reloadData() {

    }

    public Resources getResources() {
        if (resources == null) {
            resources = App.getContext().getResources();
        }
        return resources;
    }

    /**
     * 数据初始化
     */
    public abstract void initData();
}
